package com.lp.article.config;

import com.lp.model.constants.MQConstants;
import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.DirectExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class MQArticleConfig {

    @Bean
    public DirectExchange articleDirectExchange() {
        return new DirectExchange(MQConstants.ARTICLE_EXCHANGE_DIRECT, true, false);
    }

    @Bean
    public Queue visitsQueue() {
        return new Queue(MQConstants.ARTICLE_VISITS_QUEUE, true);
    }

    @Bean
    public Queue statQueue() {
        return new Queue(MQConstants.ARTICLE_STAT_QUEUE, true);
    }

    @Bean
    public Binding visitsQueueBind() {
        return BindingBuilder.bind(visitsQueue()).to(articleDirectExchange())
                        .with(MQConstants.ARTICLE_VISITS_QUEUE);
    }

    @Bean
    public Binding statQueueBind() {
        return BindingBuilder.bind(statQueue()).to(articleDirectExchange())
                        .with(MQConstants.ARTICLE_STAT_QUEUE);
    }

    @Bean
    public Queue likeQueue() {
        return new Queue(MQConstants.ARTICLE_LIKE_QUEUE, true);
    }

    @Bean
    public Binding likeBind() {
        return BindingBuilder.bind(likeQueue()).to(articleDirectExchange())
                .with(MQConstants.ARTICLE_LIKE_QUEUE);
    }

    @Bean
    public Queue collectQueue() {
        return new Queue(MQConstants.ARTICLE_COLLECT_QUEUE, true);
    }

    @Bean
    public Binding collectBind() {
        return BindingBuilder.bind(collectQueue()).to(articleDirectExchange())
                .with(MQConstants.ARTICLE_COLLECT_QUEUE);
    }

}
